package com.artislong.controller;

import org.springframework.ai.chat.messages.UserMessage;
import org.springframework.ai.chat.model.ChatModel;
import org.springframework.ai.chat.model.ChatResponse;
import org.springframework.ai.chat.prompt.Prompt;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

import java.util.Map;

/**
 * @author 陈敏
 * @version ChatController.java, v 1.0 2025 04 02 17:32 chenmin Exp $
 * Created on 2025 04 02
 */
@RestController
public class ChatController {

    @Autowired
    private ChatModel chatModel;

    @GetMapping("/chat/generate")
    public Map<String, String> generate(@RequestParam(value = "message", defaultValue = "给我讲个笑话") String message) {
        return Map.of("generation", this.chatModel.call(message));
    }

    @GetMapping("/chat/generateStream")
    public Flux<ChatResponse> generateStream(@RequestParam(value = "message", defaultValue = "给我讲个笑话") String message) {
        return this.chatModel.stream(new Prompt(new UserMessage(message)));
    }
}
